First you need to define variables and functions inside <HEAD> tag of your HTML file. Just copy the functions between <HEAD> and </HEAD> tags. After the functions are defined in <HEAD> you can easily call a welcome() function just from the place in your document where you want to have that welcome message. Oh, yes! You can edit welcome() function if you want to have other greetings.
<HTML>
<TITLE>Your document title here</TITLE>
<HEAD>
<!-- Cookie Script Written By Maxim V. Kollegov --> <!-- http://www.oocities.org/siliconvalley/lakes/8620 --> <!-- http://www.oocities.org/siliconvalley/lakes/8620/index.html -->
<SCRIPT LANGUAGE="JavaScript"> <!-- to hide script contents from old browsers
var visitor var lastvisited var countvalue
// this function extracts cookie by name and return value.
function getCookie(byname)
{byname=byname+"=";
nlen = byname.length;
fromN = document.cookie.indexOf(byname)+0;
if((fromN) != -1)
{fromN +=nlen
toN=document.cookie.indexOf(";",fromN)+0;
if(toN == -1)
{toN=document.cookie.length;}
return unescape(document.cookie.substring(fromN,toN));
} return null;
}
//this function writes to cookie
function setCookie(name,value,time)
{exp = new Date();
if((name==null)||(value==null)) return false;
if(time==null) time=365*86400000;
exp.setTime(exp.getTime()+time);
document.cookie =escape(name)+"="+escape(value)+"; "+"expires="+exp.toGMTString();
return true;
}
//this function looks into cookie for counter, visitor and lastvisited
function checkAccess()
{today=new Date();
countvalue=getCookie("counter");
visitor=getCookie("visitor");
lastvisited=getCookie("lastvisited");
if((countvalue==null)||(countvalue==""))
{countvalue="0";
visitor=prompt("Please,
Enter Your Name:","");
if((visitor==null) || (visitor==""))
visitor="Incognito";
}
countvalue=parseInt(countvalue)+1;
setCookie("counter",countvalue);
setCookie("visitor",visitor);
setCookie("lastvisited",today.toGMTString());
}
//this function writes welcome message into browser.
function welcome()
{checkAccess();
s="<center><h2>Welcome, "+visitor+"!
</h2>";
count = parseInt(countvalue);
if(count==1)
{s+="It's your first visit to my virtual
home.";}
else
{s+="You visited my page "+count+"
times. ";
s+="Last time it was "+lastvisited
+"</center>";
}
document.writeln(s);
}
// end hiding contents from old browsers -->
</SCRIPT>
</HEAD>
<BODY>
.....Your document begins here.....
Insert following row in your document, and
you will have the welcome message in browser.
<SCRIPT> welcome(); </SCRIPT>
.....Rest of your document...........
</BODY>
</HTML>